package com.simpleim.starter.handler;

import com.simpleim.im.common.bean.msg.ProtoMsg;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ChatMsgHandler extends SimpleChannelInboundHandler<ProtoMsg.Message> {

    private static final Logger LOGGER = LoggerFactory.getLogger(ChatMsgHandler.class);

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, ProtoMsg.Message msg) throws Exception {
        ProtoMsg.HeadType headType = msg.getType();
        if (!(headType == ProtoMsg.HeadType.MESSAGE_REQUEST)) {
            ctx.fireChannelRead(msg);
            return;
        }

        ProtoMsg.MessageRequest request = msg.getMessageRequest();

        LOGGER.info("收到来自：{}的消息：{}", request.getFrom(), request.getContent());
    }
}
